package edu.whu.rose.clock.ssql.index;

import java.io.UnsupportedEncodingException;

import com.sleepycat.je.DatabaseEntry;
import com.sleepycat.je.DatabaseException;
import com.sleepycat.je.Environment;

import edu.whu.rose.clock.ssql.binding.SequentialIntArrayBinding;

public class VertexIndexDB extends IndexDB {

	public VertexIndexDB(Environment dbEnv) {
		super(dbEnv, "vertexIL");
	}
	
	public VertexIndexDB(Environment dbEnv, String dbName) {
		super(dbEnv, dbName);
	}
	
	public int[] search(String keyword) {
		int[] result = null;
		try {
			DatabaseEntry list = this.get(new DatabaseEntry(keyword.toLowerCase().getBytes("UTF-8")));
			if (list == null) {
				return new int[0];
			}
			SequentialIntArrayBinding siab = new SequentialIntArrayBinding();
			Object obj = siab.entryToObject(list);
			return (int[]) obj;
			
//			String list = this.get(keyword);
//			if (list != null) {
//				String[] ids = list.split(",");
//				SequentialIntArray sia = new SequentialIntArray(ids.length);
//				for (int i = 0; i < ids.length; i++) {
//					String id = ids[i].trim();
//					if (id.length() > 0) {
//						sia.insert(new Integer(id).intValue());
//					}
//				}
//				result = sia.getArray();
//			}
		}
		catch (DatabaseException ex) {
			ex.printStackTrace();
		}
		catch (UnsupportedEncodingException ex) {
			ex.printStackTrace();
		}
		catch (NumberFormatException ex) {
			ex.printStackTrace();
		}
		return result;
	}

}
